(function(window) {
	"use strict";

	// Your starting point. Enjoy the ride!

	const vm = new Vue({
		el: "#app",
		data: {
			msg: "测试vue",
			// 存储用户输入所有数据
			list: [
				{
					id: 1,
					done: true,
					name: "aaa"
				}
			],
			// 一个标记
			editFlag: -1
		},
		methods: {
			// 处理子组件传递来的添加项
			addList(todoName) {
				let id =
					this.list.length == 0 ? 1 : this.list[this.list.length - 1].id + 1;
				this.list.push({
					id,
					name: todoName,
					done: false
				});

				console.log(this.list);
			},
			// 处理子组件传递来的内容修改请求
			editList(newName, id) {
				console.log(newName, id);
				this.list.find(item => item.id == id).name = newName;
			},
			// 处理子组件传递来的状态修改请求
			changeItemsStatus(id) {
				this.list.find(item => item.id == id).done = !this.list.find(
					item => item.id == id
				).done;
			},
			// 处理子组件传递来的删除项请求
			deleteItem(id) {
				this.list = this.list.filter(item => item.id != id);
			},
			// 处理子组件传递来的删除已经完成的项的请求
			deleteFinishedItems() {
				// console.log('开始清除已完成的');
				this.list = this.list.filter(item => item.done == false);
			}
		}
	});
})(window);
